<template>
  <van-cell class="comment-item">
    <van-image
      class="avatar"
      slot="icon"
      round
      src="https://img.yzcdn.cn/vant/cat.jpeg"
    />
    <div slot="title">
      <div class="title-wrap">
        <div class="user-name" slot="title">{{comment.aut_name}}</div>
        <div class="like-warp"
        @click="onCommentLike">
          <van-icon
          class="like-icon"
          :class="{liked: comment.is_liking}"
          slot="right-icon"
          :name="comment.is_liking?  'good-job':'good-job-o'"
           />
          <span class="like-count">{{comment.like_count}}</span>
        </div>
      </div>
        <div class="comment-content">{{comment.content}}</div>
      <div class="bottom-info">
        <span class="comment-pubdate">{{comment.pubdate | datetime('MM:DD HH:mm')}}</span>
        <van-button
         class="reply-btn"
         size="mini"
         @click="$emit('reply-click',comment)"
          type="default">{{comment.reply_count}} 回复</van-button>
      </div>
    </div>
  </van-cell>
</template>

<script>
import { addCommentLike, deleteCommentLike } from '@/api/comment'
export default {
  name: 'ItemComment',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
    }
  },
  methods: {
    async onCommentLike () {
      console.log(this.comment)
      console.log(this.comment.com_id)
      const commentId = this.comment.com_id.toString()
      if (this.comment.is_liking) {
        await deleteCommentLike(commentId)
        this.comment.like_count--
      } else {
        await addCommentLike(commentId)
        this.comment.like_count++
      }
      this.comment.is_liking = !this.comment.is_liking
    }
  }
}
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 36px;
    height: 36px;
    margin-right: 13px;
  }

 .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 14px;
    }
  }
  .like-wrap{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .like-icon.liked{
    color: #ff69b4;
  }
  .comment-content {
    font-size: 16px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 10px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 66px;
    height: 24px;
    line-height: 24px;
    font-size: 10px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
  }
}
</style>
